<?php
use yii\helpers\Html;
use yii\widgets\DetailView;

$models = $model->room; // Table OrderRoom
?>

<?=  yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>

<div class="col-md-offset-1 col-md-10 panel panel-body" style="margin-top:30px;">
    <p><label>舱房信息</label></p>
    <?php foreach($models as $mk=>$room){ ?>
    <div class="row">
        <div class="col-md-3" >
            <?= $room->productRoomPrice->productRoom->room->name ?> 
            <?= $room->productRoomPrice->productRoom->room->code ?>
            <?= $room->productRoomPrice->people ?> 人房
        </div>
        <div class="col-md-2">人数 : <?= $room->num ?></div>
        <div class="col-md-7">
            <?php $exit = yii\helpers\ArrayHelper::map($room->orderRoomCustomer, 'id', 'customer_id');?>
            <?php foreach($customers as $customer){ ?>
            <div style="float:left;margin-right:15px;">
                <input type="hidden" class="room-id" value="<?= $room->id?>">
                <input class="magic-checkbox room-magic" <?= in_array($customer->id, $exit) ? 'checked' : '' ?> type="checkbox" id="room<?= $mk.$customer->id?>" name="<?= $customer->id?>">
                <label for="room<?= $mk.$customer->id ?>" ><?= $customer->first_name . $customer->last_name ?></label>
            </div>
            <?php } ?>
        </div>
    	<a data-toggle="modal" data-target=".customer-modal"  href="/order/customer/create?order_id=<?= $model->id?>" class="pull-right btn btn-default btn-sm">添加客户</a>
    </div>
    </br>
    <?php } ?>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
    /**  add Loading  **/
    $(".room-magic").click(function(){
        var customer_id   = $(this).attr('name'); // 获取客户编号
        var order_room_id = $(this).siblings('.room-id').val(); // 获取客户编号
        var checked = $(this).is(':checked');   // 是否选中
        
        $.get("/order/room-customer/save", {customer_id:customer_id,order_room_id:order_room_id,checked:checked}, function(){

        });
    });
</script>
<?php app\components\JsBlock::end() ?>
